﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

using Aliphant.Interfaces;
using Aliphant.Mvvm.XEvent.Ioc;
using Aliphant.Mvvm.XEvent.UI;
using Aliphant.UI.Windows;

namespace Aliphant.Windows.ViewModels
{
    public class NavigationBarViewModel : BindableBase
    {
        private IUIContainer _container;


        public NavigationBarViewModel()
        {
            _container = UIContainerLocator.Container;
            GlobalProperty.NavigatedEvent += UpdateRadioCheck;

            WallpaperVisible = _container.ContainsKey("wallpaper") ? Visibility.Visible : Visibility.Collapsed;
            BrowserVisible = _container.ContainsKey("browser") ? Visibility.Visible : Visibility.Collapsed;
            ChatAIVisible = _container.ContainsKey("chatRobot") ? Visibility.Visible : Visibility.Collapsed;
            WidgetVisible = _container.ContainsKey("widgets") ? Visibility.Visible : Visibility.Collapsed;
        }


        private bool _wallpaperChecked = false;
        public bool WallpaperChecked { get => _wallpaperChecked; set => SetProperty(ref _wallpaperChecked, value); }

        private Visibility _wallpaperVisible;
        public Visibility WallpaperVisible { get => _wallpaperVisible; set => SetProperty(ref _wallpaperVisible, value); }


        private bool _browserChecked;
        public bool BrowserChecked { get => _browserChecked; set => SetProperty(ref _browserChecked, value); }

        private Visibility _browserVisible;
        public Visibility BrowserVisible { get => _browserVisible; set => SetProperty(ref _browserVisible, value); }


        private bool _chatAIChecked;
        public bool ChatAIChecked { get => _chatAIChecked; set => SetProperty(ref _chatAIChecked, value); }

        private Visibility _chatAIVisible;
        public Visibility ChatAIVisible { get => _chatAIVisible; set => SetProperty(ref _chatAIVisible, value); }


        private bool _widgetChecked;
        public bool WidgetChecked { get => _widgetChecked; set => SetProperty(ref _widgetChecked, value); }

        private Visibility _widgetVisible;
        public Visibility WidgetVisible { get => _widgetVisible; set => SetProperty(ref _widgetVisible, value); }


        private bool _settingChecked;
        public bool SettingChecked { get => _settingChecked; set => SetProperty(ref _settingChecked, value); }



        public ICommand NavigateToWallpaper
        {
            get => new UICommand<object>(obj =>
            {
                _container.NavigateTo("main", "wallpaper");
                Application.Current.MainWindow.Title = "Cute Wallpaper";
            });
        }

        public ICommand NavigateToBrowser
        {
            get => new UICommand<object>(obj =>
            {
                _container.NavigateTo("main", "browser");
                Application.Current.MainWindow.Title = "XBrowser";
            });
        }

        public ICommand NavigateToChatAI
        {
            get => new UICommand<object>(obj =>
            {
                _container.NavigateTo("main", "chatRobot");
                Application.Current.MainWindow.Title = "XChatAI";
            });
        }

        public ICommand NavigateToWidget
        {
            get => new UICommand<object>(obj =>
            {
                _container.NavigateTo("main", "widgets");
                Application.Current.MainWindow.Title = "XWidget";
            });
        }

        public ICommand NavigateToSetting
        {
            get => new UICommand<object>(obj =>
            {
                _container.NavigateTo("main", "settings");
                Application.Current.MainWindow.Title = "设置";
            });
        }

        public ICommand NavigateToWidgetCenter
        {
            get => new UICommand<object>(obj =>
            {
                _container.NavigateTo("main", "widgetCenter");
                Application.Current.MainWindow.Title = "XWidgetCenter(Testing)";
            });
        }



        public void UpdateRadioCheck(string page)
        {
            WallpaperChecked = false;
            BrowserChecked = false;
            SettingChecked = false;

            switch (page)
            {
                case "wallpaper":
                    _container.NavigateTo("main", "wallpaper");
                    Application.Current.MainWindow.Title = "Cute Wallpaper";
                    WallpaperChecked = true;
                    break;
                case "browser":
                    _container.NavigateTo("main", "browser");
                    Application.Current.MainWindow.Title = "XBrowser";
                    BrowserChecked = true;
                    break;
                case "settings":
                    _container.NavigateTo("main", "settings");
                    Application.Current.MainWindow.Title = "设置";
                    SettingChecked = true;
                    break;
            }
        }
    }
}
